home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / allocwg.com / CALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-10  |  1.0 KB  |  39 lines

  1. #if defined (NMSC)
  2.  
  3.     /*  Non-MSC Version  */
  4.  
  5. #if (defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM))
  6.  
  7.     /*  NOTE:  These procedures should only be used for
  8.                large data model programs (i.e., Compact, Large, Huge) */
  9.  
  10. #include <stddef.h>
  11. #include "alloc.h"
  12.  
  13. void *calloc ( n, nbytes )
  14.  
  15.    size_t       n       ;        /* Number of units of size nbytes   */
  16.    size_t       nbytes  ;        /* Number of bytes to allocate      */
  17.  
  18. /*
  19.          +------------------------------------------+
  20.          |                                          |  
  21.          |  Memory allocation with initialization   |  
  22.          |                                          |  
  23.          +------------------------------------------+
  24. */
  25.  
  26. {
  27.    void *malloc () ;
  28.    void *block     ;
  29.    long  bsize     ;
  30.  
  31.    if ((bsize = (long) n * (long) nbytes) > (long) MAXALLOC )
  32.       return ( NULL ) ;
  33.    if ((block = malloc ( (size_t) bsize )) != NULL )
  34.       memset ( (char *) block, 0, (size_t) bsize ) ;
  35.    return ( block ) ;
  36. }
  37. #endif
  38. #endif
  39.